package com.rla.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.rla.common.annotation.Anonymous;
import com.rla.common.utils.validate.AddGroup;
import com.rla.common.utils.validate.EditGroup;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.rla.common.annotation.RepeatSubmit;
import com.rla.common.annotation.Log;
import com.rla.common.core.controller.BaseController;
import com.rla.common.core.domain.PageQuery;
import com.rla.common.core.domain.R;
import com.rla.common.enums.BusinessType;
import com.rla.common.utils.poi.ExcelUtil;
import com.rla.domain.vo.BasePicUrlVo;
import com.rla.domain.bo.BasePicUrlBo;
import com.rla.service.IBasePicUrlService;
import com.rla.common.core.page.TableDataInfo;

/**
 * 图片及跳转描述
 *
 * @author rla
 * @date 2025-07-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/shop/pic")
public class BasePicUrlController extends BaseController {

    private final IBasePicUrlService iBasePicUrlService;

    /**
     * 查询图片及跳转描述列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo<BasePicUrlVo> list(BasePicUrlBo bo, PageQuery pageQuery) {
        return iBasePicUrlService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出图片及跳转描述列表
     */
    @Log(title = "图片及跳转描述", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BasePicUrlBo bo, HttpServletResponse response) {
        List<BasePicUrlVo> list = iBasePicUrlService.queryList(bo);
        ExcelUtil.exportExcel(list, "图片及跳转描述", BasePicUrlVo.class, response);
    }

    /**
     * 获取图片及跳转描述详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<BasePicUrlVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iBasePicUrlService.queryById(id));
    }

    /**
     * 新增图片及跳转描述
     */
    @Log(title = "图片及跳转描述", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BasePicUrlBo bo) {
        return toAjax(iBasePicUrlService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改图片及跳转描述
     */
    @Log(title = "图片及跳转描述", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BasePicUrlBo bo) {
        return toAjax(iBasePicUrlService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除图片及跳转描述
     *
     * @param ids 主键串
     */
    @Log(title = "图片及跳转描述", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iBasePicUrlService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * app首页获取轮播或金刚区
     */
    @Anonymous
    @GetMapping("/app/index/list")
    public R<Map<String,Object>> getAppIndexList(BasePicUrlBo bo) {
        return R.ok(iBasePicUrlService.getAppIndexList(bo));
    }

    /**
     * app科普页面专家团队和集团简介图片视频
     */
    @Anonymous
    @GetMapping("/app/expertScience/list")
    public R<Map<String,Object>> getAppExpertScienceList(BasePicUrlBo bo) {
        return R.ok(iBasePicUrlService.getAppExpertScienceList(bo));
    }


}
